package com.dialogutils;

import android.app.Activity;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import androidx.appcompat.app.AlertDialog;
import com.systemutils.ScreenSize;

public abstract class FullScreenDialog extends AlertDialog {
    private float mWidthPixels = 0;
    private float mHeightPixels = 0;
    protected Activity mContext;

    protected FullScreenDialog(Context context) {
        this(context, 0);
    }

    protected FullScreenDialog(Context context, int themeResId) {
        super(context, themeResId);
        this.mContext = (Activity) context;
    }

    protected FullScreenDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        this.mContext = (Activity) context;
    }

    protected void showDialog() {
        show();
        setCanceledOnTouchOutside(false);
        setContentView(loadView());
        onCreate();
    }

    @Override
    public void show() {
        super.show();
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.gravity = Gravity.CENTER;
        layoutParams.width = (int) mWidthPixels;
        layoutParams.height = (int) mHeightPixels;
        getWindow().getDecorView().setPadding(0, 0, 0, 0);
        getWindow().setAttributes(layoutParams);
    }

    public void setWeight(float width, float height) {
        this.mWidthPixels = ScreenSize.getWindowWidthPixels((Activity) mContext) * width;
        this.mHeightPixels = ScreenSize.getWindowHighPixels((Activity) mContext) * height;
    }

    public void setSize(float width, float height) {
        this.mWidthPixels = width;
        this.mHeightPixels = height;
    }

    public void onDestory(){

    }

    protected abstract View loadView();
    protected abstract void onCreate();
}
